<template>
	<nt-container>
		<view class="setting">
			<!-- #ifdef APP-PLUS -->
			<nt-card-item label="我的位置" is-link @tap="nav(`/subpackage/member/pages/location/location`)">
			</nt-card-item>
			<!-- #endif -->
			<nt-card-item label="开发页面" is-link @tap="nav(`/subpackage/mine/pages/ratetips/index`)"></nt-card-item>

			<nt-card-item label="关于" is-link :desc="`当前版本：${sysInfo.appVersion}`"
				@tap="nav(`/subpackage/member/pages/about/index`)"></nt-card-item>
			<!-- <nt-card-item label="申请解约" is-link></nt-card-item> -->
			<nt-card-item label="权限设置" is-link
				@click="nav(`/subpackage/member/pages/setting/permision`)"></nt-card-item>
			<nt-card-item label="首页缓存">
				<template #desc>
					<u-switch v-model="$store.state.app.indexCache" @change="changeIndexCache"></u-switch>
				</template>
			</nt-card-item>
			<nt-card-item label="开发测试专用" is-link @click="nav(`/pages/test/index`)"
				v-if="[19911, 9].includes(userInfo.id)"></nt-card-item>

			<nt-card-item label="账号注销" @click="clickApplyAccountCancellation()"></nt-card-item>
			<nt-card-item label="软件许可协议" is-link @click="readAgreement(1)"></nt-card-item>
			<nt-card-item label="隐私政策" is-link @click="readAgreement(2)"></nt-card-item>
			<nt-card-item label="服务监督协议" is-link @click="readAgreement(3)"></nt-card-item>

			<nt-button text="退出登录" @click="show = true"></nt-button>
		</view>
		<u-modal :show="show" title="温馨提示" content='确定退出当前登录吗？' @confirm="userLogout" @cancel="show = false"
			show-cancel-button></u-modal>
	</nt-container>
</template>

<script>
	import {
		applyAccountCancellation
	} from "@/api"
	import {
		mapActions,
		mapGetters,
		mapState
	} from "vuex"
	export default {
		data() {
			return {
				show: false,
				desc: "",
			}
		},
		computed: {
			...mapGetters(["sysInfo", "userInfo", "location"])
		},
		methods: {
			async userLogout() {
				await this.$store.dispatch("user/logout")
				this.$store.dispatch('user/clearLocation')
			},
			clickApplyAccountCancellation() {
				var postData = {};
				applyAccountCancellation(postData).then(res => {
					const {
						code,
						msg
					} = res;
					if (code === 1) {
						this.toast(msg)
					}
				})
			},
			changeIndexCache(e) {
				console.log(e)
				this.$store.commit('app/SET_INDEX_CACHE', e)
			},
			readAgreement(index) {
				let src = ""
				switch (index) {
					case 1:
						src = "https://m.nantianit.com/apiv2/xy/protocol?funtype=rjxy"
						break
					case 2:
						src = "https://m.nantianit.com/apiv2/xy/protocol?funtype=ysxy"
						break
					case 3:
						src = "https://m.nantianit.com/apiv2/xy/protocol?funtype=fwxy"
						break
				}
				this.nav('/pages/webview/index?src=' + src)
			}
		}
	}
</script>

<style scoped lang="scss">
	.setting {
		padding: 30rpx;
		box-sizing: border-box;
		background: #fff;

		/deep/ .button-container {
			position: fixed;
			bottom: 100rpx;
			left: 30rpx;
			right: 30rpx;
			border-radius: 0;

		}
	}
</style>